from tools.utils import do_rest

class QueryRolePage():
    """角色管理"""
    def __init__(self):
        self.url = 'https://xxxxxx/xx'

    def query_role(self, roleName=None):
        """查询角色的id"""
        data = {"cdt": {"roleName": roleName}, "pageNum": 1, "pageSize": 30, "orders": "CREATE_TIME DESC"}
        response = do_rest(self.url, param=data, method='post')
        return response.json()

    def query_role_id(self, roleName):
        """获取角色的id"""
        re_json_data = self.query_role(roleName)['data']['data']
        for i in re_json_data:
            if i['roleName'] == roleName:
                return i['id']
        else:
            raise ValueError('请输入正确的角色名称！')
